<%@ page import="com.grouplay.entity.User" %><%--
  Created by IntelliJ IDEA.
  User: YYW
  Date: 2020/5/29
  Time: 18:12
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="UTF-8">
    <link href="./css/bootstrap.min.css" rel="stylesheet">
    <script src="./js/jquery.min.js"></script>
    <script src="./js/bootstrap.min.js"></script>
    <script src="./js/jquery.form.min.js"></script>
    <script src="https://unpkg.com/xlsx/dist/xlsx.full.min.js"></script>
    <%if (session.getAttribute("user") == null) {
        out.print("    <script type=\"text/javascript\">\n" +
                "        $.ajax({\n" +
                "            url:\"./user/login\",\n" +
                "            success:function (result) {\n" +
                "                var data = eval(result);\n" +
                "                if (data){\n" +
                "                    location.replace(\".\");\n" +
                "                }\n" +
                "            }\n" +
                "        })\n" +
                "    </script>");
    }%>
</head>
<body>
<div class="container-fluid" style="margin-top:20px; margin-left: 20px; margin-right: 20px;">
    <div class="row">
        <nav class="navbar navbar-default" role="navigation">
            <div class="container-fluid">
                <div class="navbar-header">
                    <a class="navbar-brand" href="WEB-INF/pages">GROUPLAY</a>
                </div>
                <div>
                    <ul class="nav navbar-nav">
                        <li class="active"><a href="WEB-INF/pages">主页</a></li>
                        <li><a href="register.jsp">注册</a></li>
                        <li><a href="./join.jsp">加入我们</a></li>
                        <li><a href="images/sponsor.jpg" target="_blank">赞助</a></li>
                    </ul>
                    <ul class="nav navbar-nav navbar-right">
                        <%if (session.getAttribute("user") != null){
                            User user = (User) session.getAttribute("user");
                            out.print("<li><a href='.'>欢迎" + user.getName() + "</a></li>");
                            out.print("<li><a href='./user/logout'>退出</a></li>");
                        } else {
                            out.print("<li><a href='./login.jsp'>去登录</a></li>");
                        }%>
                    </ul>
                </div>
            </div>
        </nav>
    </div>
    <div class="row-fluid">
        <div class="col-xs-2">
            <ul class="nav nav-pills nav-stacked">
                <li class="leftli active" id="showRotation"><a>热门景点</a></li>
                <li class="leftli" id="showInformationMaintenance"><a>信息维护</a></li>
                <li class="leftli" id="showCreateGroup"><a>创建团队</a></li>
                <li class="leftli" id="showMyGroups"><a>我创建的团队</a></li>
                <li class="leftli" id="showMyJoinGroups"><a>我加入的团队</a></li>
                <li class="leftli" id="showInviteMe"><a><span id="myInviteMeCountTip" class="badge pull-right"></span>邀请函</a></li>
                <li class="leftli" id="showSendMessage"><a>发消息</a></li>
                <li class="leftli" id="showMyInbox"><a><span id="messagesCountTip" class="badge pull-right"></span>收件箱</a></li>
                <li class="leftli" id="myAccount"><a>我的账户</a></li>
            </ul>
        </div>
        <div id="show" class="col-xs-8">

        </div>
        <div class="col-xs-2">
            <h2>
                拼团
            </h2>
            <p>
                拼团自由玩是您组团外出游玩的不二之选，您可以发起发起创建团队，确定活动起始时间、内容（行程）、总预算、个人预算等
            </p>
            <p>
                <a class="btn" href="teaching.html" target="_blank">查看教程 »</a>
            </p>
        </div>
    </div>
</div>

<div class="modal fade" id="noFinishedGroupModal" tabindex="-1" role="dialog" aria-labelledby="noFinishedGroupModal" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="noFinishedGroupModalGroupName"></h4>
            </div>
            <div class="modal-body input-group" style="width: 100%">
                <form class="form-horizontal" role="form">
                    <div class="form-group">
                        <label for="beInvitedUserName" class="col-sm-offset-1 col-sm-3 control-label">邀请用户：</label>
                        <div class="col-sm-5">
                            <input type="text" class="form-control" id="beInvitedUserName" name="beInvitedUserName" required placeholder="请输入用户名"/>
                        </div>
                        <input type="hidden" name="inviteGroupId" id="inviteGroupId" value=""/>
                        <button type="button" onclick="inviteUserToMyGroup()" class="btn btn-default">邀请</button>
                    </div>
                </form>
                <hr>
                <div id="showMemberName">

                </div>
                <hr>
                <form class="form-horizontal" role="form" id="updateMyGroupForm">
                    <div class="form-group">
                        <label for="totalBudget" class="col-sm-3 control-label">总预算：</label>
                        <div class="col-sm-8">
                            <input type="number" class="form-control" id="totalBudget" step="0.01" name="totalBudget" required/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="personalBudget" class="col-sm-3 control-label">个人预算：</label>
                        <div class="col-sm-8">
                            <input type="number" class="form-control" id="personalBudget" step="0.01" name="personalBudget" required/>
                        </div>
                    </div>
                    <input type="hidden" name="updateGroupId" id="updateGroupId" value=""/>
                    <div class="form-group">
                        <div class="col-sm-offset-3 col-sm-9">
                            <button type="button" onclick="updateMyGroup()" class="btn btn-default">更新</button>
                        </div>
                    </div>
                </form>
                <button class="btn btn-default" onclick="endGroup()">结束活动</button>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>

<div class="modal fade" id="inviteMeModel" tabindex="-1" role="dialog" aria-labelledby="inviteMeModel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <p id="inviteMeModelHeader">

                </p>
            </div>
            <div class="modal-body input-group" style="width: 100%">
                <p id="inviteMeModelBody">

                </p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-success" id="inviteMeModelFooterJoin">加入</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>

<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>

<script type="text/javascript">

    function updateMyGroup(){
        $.ajax({
            url:"./user/updateMyGroupBudget?id=" + $("#updateGroupId").val() + "&personalBudget=" + $("#personalBudget").val() + "&totalBudget=" + $("#totalBudget").val(),
            success:function (result) {
                var data = eval(result);
                if (data){
                    alert("更新成功");
                    loadMyGroups();
                } else {
                    alert("更新失败");
                }
            },
            error:function () {
                alert("更新失败");
            }
        })
    }

    $(function () {
        $.ajax({
            url:"./rotation.html",
            success:function (result) {
                $("#show")[0].innerHTML = result;
            }
        });
        loadMyMessages();
        loadInviteMes();
        setInterval(function () {
            loadMyMessages();
            loadInviteMes();
        }, 5000);
    });

    document.getElementById("showRotation").onclick = function (ev) {
        $.ajax({
            url:"./rotation.html",
            success:function (result) {
                $("#show")[0].innerHTML = result;
                leftliSetOneActive("showRotation");
            }
        });
    };

    document.getElementById("myAccount").onclick = function (ev) {
        $.ajax({
            url:"./myAccount.jsp",
            success:function (result) {
                $("#show")[0].innerHTML = result;
                leftliSetOneActive("myAccount");
                loadMyAccount();
            }
        });
    };

    document.getElementById("showInformationMaintenance").onclick = function (ev) {
        $.ajax({
            url:"./informationMaintenance.jsp",
            success:function (result) {
                $("#show")[0].innerHTML = result;
                leftliSetOneActive("showInformationMaintenance");
            }
        });
    };

    document.getElementById("showMyGroups").onclick = function (ev) {
        $.ajax({
            url:"./myGroups.jsp",
            success:function (result) {
                $("#show")[0].innerHTML = result;
                leftliSetOneActive("showMyGroups");
                loadMyGroups();
            }
        });
    };

    document.getElementById("showCreateGroup").onclick = function (ev) {
        $.ajax({
            url:"./createGroup.jsp",
            success:function (result) {
                $("#show")[0].innerHTML = result;
                leftliSetOneActive("showCreateGroup");
            }
        });
    };

    document.getElementById("showSendMessage").onclick = function (ev) {
        $.ajax({
            url:"./sendMessage.jsp",
            success:function (result) {
                $("#show")[0].innerHTML = result;
                leftliSetOneActive("showSendMessage");
            }
        });
    };

    document.getElementById("showMyInbox").onclick = function (ev) {
        $.ajax({
            url:"./myInbox.jsp",
            success:function (result) {
                $("#show")[0].innerHTML = result;
                leftliSetOneActive("showMyInbox");
                loadMyMessages();
            }
        });
    };

    document.getElementById("showMyJoinGroups").onclick = function (ev) {
        $.ajax({
            url:"./myJoinGroups.jsp",
            success:function (result) {
                $("#show")[0].innerHTML = result;
                leftliSetOneActive("showMyJoinGroups");
                loadMyJoinGroups();
            }
        });
    };

    document.getElementById("showInviteMe").onclick = function (ev) {
        $.ajax({
            url:"./inviteMe.jsp",
            success:function (result) {
                $("#show")[0].innerHTML = result;
                leftliSetOneActive("showInviteMe");
                loadInviteMes();
            }
        });
    };




    function leftliSetOneActive(id) {
        var lis = document.getElementsByClassName("leftli");
        for (var i = 0; i < lis.length; i ++){
            lis[i].className = "leftli";
        }
        document.getElementById(id).className = "leftli active";
    }

    function transfer() {
        $.ajax({
            url:"./user/transferMoney?transferTargetName=" + $("#transferTargetName").val() + "&transferMoney=" + $("#transferMoney").val(),
            success:function (result) {
                var data = eval(result);
                if (data) {
                    alert("转账成功");
                } else {
                    alert("转账失败");
                }
                $("#transferTargetName")[0].value = "";
                $("#transferMoney")[0].value = "";
                loadMyAccount();
            }
        })
    }

    var balance;
    var myNotPay;
    function loadMyAccount() {
        $.ajax({
            url:"./user/myBalance",
            success:function (result) {
                balance = eval(result);
                $("#balanceTip")[0].innerHTML = result;
            }
        });
        $.ajax({
            url:"./user/loadMyNotPay",
            success:function(result) {
                var data = eval(result);
                myNotPay = data;
                var inHtml = "";
                if (data.length == 0) {
                    inHtml = "无代办事项";
                } else {
                    inHtml = "<table class=\"table\">\n" +
                        "    <thead>\n" +
                        "    <tr>\n" +
                        "        <th>团队名</th>\n" +
                        "        <th>创建者</th>\n" +
                        "        <th>需支付（￥）</th>\n" +
                        "        <th>操作</th>\n" +
                        "    </tr>\n" +
                        "    </thead>\n" +
                        "    <tbody id=\"myGroupTableTbody\">";
                    for (var i = 0; i < data.length; i ++) {
                        inHtml += "<tr class='success'>";
                        inHtml += "<td>" + data[i].groupName + "</td>";
                        inHtml += "<td>" + data[i].leaderName + "</td>";
                        inHtml += "<td>" + data[i].needMoney + "</td>";
                        inHtml += "<td><a onclick='pay(" + data[i].id + ")'>支付</a></td>";
                        inHtml += "</tr>";
                    }
                    inHtml += "</tbody></table>";
                }
                $("#unpaidBox")[0].innerHTML = inHtml;
            }
        });
        $.ajax({
            url:"./user/myTransferRecord",
            success:function (result) {
                var data = eval(result);
                var transferRecordTbody = document.getElementById("transferRecordTbody");
                if (transferRecordTbody) {
                    var inHtml = "";
                    for (var i = 0; i < data.length; i ++) {
                        if (data[i].isTransferOut == 1) {
                            inHtml += "<tr class='danger'>";
                        } else {
                            inHtml += "<tr class='success'>"
                        }
                        if (data[i].isTransferOut == 1) {
                            inHtml += "<td>" + data[i].targetName + "</td>";
                            inHtml += "<td>-" + data[i].money + "</td>";
                        } else {
                            inHtml += "<td>" + data[i].sourceName + "</td>";
                            inHtml += "<td>+" + data[i].money + "</td>";
                        }
                        var date = new Date(data[i].date);
                        inHtml += "<td>" + date.toLocaleDateString() + date.toLocaleTimeString() + "</td>";
                        if (data[i].groupName == null) {
                            inHtml += "<td>转账</td>";
                        } else {
                            inHtml += "<td>'" + data[i].groupName + "'团队团费</td>";
                        }
                        inHtml += "</tr>";
                    }
                    transferRecordTbody.innerHTML = inHtml;
                }
            }
        })
    }

    function pay(groupId) {
        $.ajax({
            url:"./user/pay?groupId=" + groupId,
            success:function (result) {
                var data = eval(result);
                if (data) {
                    alert("支付成功");
                } else {
                    alert("支付失败");
                }
                loadMyAccount();
            }
        })
    }


    function setNewName() {
        $("#setNewNameForm").ajaxSubmit({
            success:function (result) {
                var data = eval(result);
                if (data){
                    alert("修改成功");
                    location.replace(".");
                } else {
                    alert("修改失败");
                }
            }
        });
        return false;
    }

    var myJoinGroups;
    function loadMyJoinGroups() {
        $.ajax({
            url:"./user/loadMyJoinGroups",
            success:function (result) {
                var data = eval(result);
                myJoinGroups = data;
                var myJoinGroupTableTbody = document.getElementById("myJoinGroupTableTbody");
                if (myJoinGroupTableTbody) {
                    var inHtml = "";
                    for (var i = 0; i < data.length; i ++){
                        if (data[i].isEnd == 0) {
                            inHtml += "<tr class='success'>";
                        } else {
                            inHtml += "<tr>";
                        }
                        inHtml += "<td>" + data[i].groupName + "</td>";
                        inHtml += "<td>" + data[i].leaderName + "</td>";
                        inHtml += "<td>" + data[i].totalBudget + "</td>";
                        inHtml += "<td>" + data[i].personalBudget + "</td>";
                        inHtml += "<td>" + (data[i].totalBudget - data[i].personalBudget) / (data[i].numberOfMembers - 1) + "</td>";
                        console.log(data[i].beginTime);
                        var beginDate = new Date(data[i].beginTime);
                        inHtml += "<td>" + beginDate.getFullYear() + "/" + (beginDate.getMonth() + 1) + "/" + beginDate.getDate() + "</td>";
                        if (data[i].endTime != null){
                            var endDate = new Date(data[i].endTime);
                            inHtml += "<td>" + endDate.getFullYear() + "/" + (endDate.getMonth() + 1) + "/" + endDate.getDate() + "</td>";
                        } else {
                            inHtml += "<td>未结束</td>";
                        }
                        inHtml += "<td>" + data[i].numberOfMembers + "</td>"
                        if (data[i].isEnd == 0) {
                            inHtml += "<td><a>退出</a></td>"
                        } else {
                            inHtml += "<td><a onclick='downloadBudgetByGroupId(" + data[i].id + ")' data-toggle='tooltip' title='导出'><span class='glyphicon glyphicon-download-alt'></span></a></td>";
                        }
                        inHtml += "</tr>";
                    }
                    myJoinGroupTableTbody.innerHTML = inHtml;
                }
            }
        });
    }

    function createGroup() {
        if (eval($("#totalBudget").val()) < eval($("#personalBudget").val())){
            alert("个人预算应小于等于总预算");
            return false;
        }
        $("#createGroupForm").ajaxSubmit({
            success:function (result) {
                var data = eval(result);
                if (data){
                    alert("创建成功");
                    location.replace(".");
                } else {
                    alert("创建失败");
                }
            }
        });
        return false;
    }

    function sendMessage() {
        $("#sendMessageForm").ajaxSubmit({
            success:function (result) {
                var data = eval(result);
                if (data){
                    alert("发送成功");
                    location.replace(".");
                } else {
                    alert("发送失败");
                }
            }
        });
        return false;
    }

    function inviteUserToMyGroup() {
        $.ajax({
            url:"./user/inviteUserToMyGroup?inviteGroupId=" + $("#inviteGroupId").val() + "&beInvitedUserName=" + $("#beInvitedUserName").val(),
            success:function (result) {
                var data = eval(result);
                if (data){
                    alert("邀请信息已发送");
                } else {
                    alert("该用户不存在或已经在团队中");
                }
            }
        });
    }

    var endGroupId;
    function endGroup() {
        $.ajax({
            url:"./user/endGroup?groupId=" + endGroupId,
            success:function (result) {
                var data = eval(result);
                if (data) {
                    alert("已结束该活动");
                } else {
                    alert("操作失败");
                }
                loadMyGroups();
            }
        });
    }

    function showNoFinishedGroupModal(groupIndex) {
        var group = myGroups[groupIndex];
        $("#noFinishedGroupModalGroupName")[0].innerHTML = group.groupName;
        // 获取组内成员
        $("#inviteGroupId")[0].value = group.id;
        $("#updateGroupId")[0].value = group.id;
        endGroupId = group.id;
        $.ajax({
            url:"./user/getOtherUser?groupId=" + group.id,
            success: function (result) {
                var data = eval(result);
                if (data.length == 0) {
                    $("#showMemberName")[0].innerHTML = "无其他成员";
                }else {
                    var temp = "其他成员：";
                    for (var i = 0; i < data.length; i ++){
                        temp += "<br>" + data[i].name;
                    }
                    $("#showMemberName")[0].innerHTML = temp;
                }
            }
        });
        $("#totalBudget")[0].value = group.totalBudget;
        $("#personalBudget")[0].value = group.personalBudget;
        $("#noFinishedGroupModal").modal("show");
    }

    var myGroups = null;
    function loadMyGroups() {
        $.ajax({
            type:"get",
            url:"./user/getMyGroups",
            success:function (result) {
                var data = eval(result);
                var myGroupTableTbody = document.getElementById("myGroupTableTbody");
                if (myGroupTableTbody) {
                    myGroups = data;
                    var inHtml = "";
                    for (var i = 0; i < data.length; i ++){
                        if (data[i].isEnd == 0) {
                            inHtml += "<tr class='success'>";
                        } else {
                            inHtml += "<tr>";
                        }
                        inHtml += "<td>" + data[i].groupName + "</td>";
                        inHtml += "<td>" + data[i].totalBudget + "</td>";
                        inHtml += "<td>" + data[i].personalBudget + "</td>"
                        var beginDate = new Date(data[i].beginTime);

                        inHtml += "<td>" + beginDate.getFullYear() + "/" + (beginDate.getMonth() + 1) + "/" + beginDate.getDate() + "</td>";
                        if (data[i].endTime != null){
                            var endDate = new Date(data[i].endTime);
                            inHtml += "<td>" + endDate.getFullYear() + "/" + (endDate.getMonth() + 1) + "/" + endDate.getDate() + "</td>";
                        } else {
                            inHtml += "<td>未结束</td>";
                        }
                        if (data[i].isEnd == 0) {
                            inHtml += "<td><a onclick='showNoFinishedGroupModal(" + i + ")' data-toggle='tooltip' title='操作'><span class='glyphicon glyphicon-pencil'></span></a></td>"
                        } else {
                            inHtml += "<td><a onclick='downloadBudgetByGroupId(" + data[i].id + ")' data-toggle='tooltip' title='导出'><span class='glyphicon glyphicon-download-alt'></span></a></td>";
                        }
                        inHtml += "</tr>";
                    }
                    myGroupTableTbody.innerHTML = inHtml;
                }
            }
        });
    }

    function downloadBudgetByGroupId(groupId) {
        $.ajax({
            url:"./user/downloadBudgetByGroupId?groupId=" + groupId,
            success:function (result){
                var result = JSON.stringify(result);
                result = result.replace(/groupName/g, "团队名").replace(/payer/g, "用户名").replace(/payMoney/g, "支付金额").replace(/totalMoney/g, "总金额").replace(/isLeader/g, "是否为团长");
                var data = eval(result);
                for (var i = 0; i < data.length; i ++) {
                    if (data[i].是否为团长 == 0) {
                        data[i].是否为团长 = "否";
                    } else {
                        data[i].是否为团长 = "是";
                    }
                }
                if (data.length > 0) {
                    var wb = XLSX.utils.book_new();
                    var ws = XLSX.utils.json_to_sheet(data);
                    XLSX.utils.book_append_sheet(wb, ws, "SheetJS");
                    XLSX.writeFile(wb, "'" + data[0].团队名 +  "'团队缴费情况统计.xlsx");
                }
            }
        })
    }
    
    function OneTransferRecord(tr) {
        var transferName;
        var money;
        var time;
        var description;
        if (tr.isTransferOut == 1) {
            transferName = tr.targetName;
            money = "-" + tr.money + "￥";
        } else {
            transferName = tr.sourceName;
            money = "+" + tr.money + "￥";
        }
        var date = new Date(tr.date);
        time = date.toLocaleDateString() + date.toLocaleTimeString();
        if (tr.groupName) {
            description = "'" + tr.groupName + "'团队团费";
        } else {
            description = "普通转账";
        }
        this.转账用户 = transferName;
        this.金额 = money;
        this.时间 = time;
        this.备注 = description;
    }
    
    function downloadMyBudget() {
        $.ajax({
            url:"./user/myTransferRecord",
            success:function (result) {
                var data = [];
                for (var i = 0; i < result.length; i ++) {
                    data.push(new OneTransferRecord(result[i]));
                }
                var wb = XLSX.utils.book_new();
                var ws = XLSX.utils.json_to_sheet(data);
                XLSX.utils.book_append_sheet(wb, ws, "SheetJS");
                XLSX.writeFile(wb, "转账记录.xlsx");
            }
        })
    }

    var myMessages = null;
    function loadMyMessages() {
        $.ajax({
            type:"get",
            url:"./user/getTenMessages",
            success:function (result) {
                var data = eval(result);
                myMessages = data;
                var countNotLook = 0;
                for (var i = 0; i < data.length; i ++){
                    if (data[i].hasBeenLooked == 0){
                        countNotLook ++;
                    }
                }
                if (countNotLook > 0) {
                    $("#messagesCountTip")[0].innerHTML = "" + countNotLook;
                } else {
                    $("#messagesCountTip")[0].innerHTML = "";
                }
                var myInboxTableTbody = document.getElementById("myInboxTableTbody");
                if (myInboxTableTbody) {
                    var inHtml = "";
                    for (var i = 0; i < data.length; i ++){
                        if (data[i].hasBeenLooked == 0) {
                            inHtml += "<tr class='success'>";
                        } else {
                            inHtml += "<tr>";
                        }
                        inHtml += "<td>" + data[i].sourceName + "</td>";
                        inHtml += "<td>" + data[i].message + "</td>";
                        var date = new Date(data[i].date);
                        inHtml += "<td>" + date.toLocaleDateString() + date.toLocaleTimeString() + "</td>"
                        if (data[i].hasBeenLooked == 0){
                            inHtml += "<td><a onclick='markRead(" + data[i].id +")'>标记已读</a></td>"
                        } else {
                            inHtml += "<td><a>删除</a></td>"
                        }
                    }
                    myInboxTableTbody.innerHTML = inHtml;
                }
            }
        });
    }

    function markRead(id) {
        $.ajax({
            url:"./user/markRead?id=" + id,
            type:"get",
            success:function (result) {
                loadMyMessages();
            }
        })
    }

    var inviteMes = null;
    function loadInviteMes() {
        $.ajax({
            type:"get",
            url:"./user/inviteMe",
            success:function (result) {
                var data = eval(result);
                inviteMes = data;
                var countNotLook = data.length;
                if (countNotLook > 0) {
                    $("#myInviteMeCountTip")[0].innerHTML = "" + countNotLook;
                } else {
                    $("#myInviteMeCountTip")[0].innerHTML = "";
                }
                var inviteMeTableTbody = document.getElementById("inviteMeTableTbody");
                if (inviteMeTableTbody) {
                    var inHtml = "";
                    for (var i = 0; i < data.length; i ++){
                        inHtml += "<tr>";
                        inHtml += "<td>" + data[i].groupName + "</td>";
                        inHtml += "<td>" + data[i].leaderName + "</td>";
                        var date = new Date(data[i].date);
                        inHtml += "<td>" + date.toLocaleDateString() + date.toLocaleTimeString() + "</td>"
                        inHtml += "<td><a onclick='showInviteMeModel(" + data[i].groupId + ")'>查看</a></td>";
                        inHtml += "<td><a href=''>删除</a></td>";
                        inHtml += "</tr>";
                    }
                    inviteMeTableTbody.innerHTML = inHtml;
                }
            }
        });
    }

    function showInviteMeModel(groupId) {
        $.ajax({
            url:"./user/lookGroupDetails?groupId=" + groupId,
            success:function (result) {
                if (result == "") {
                    return;
                }
                var data = eval(result);
                $("#inviteMeModelHeader")[0].innerHTML = data.leaderName + "邀请您加入'" + data.groupName + "'团队";
                $("#inviteMeModelBody")[0].innerHTML =
                    "<h4>自由玩旅程：</h4><br>" +
                    "&nbsp;&nbsp;&nbsp;&nbsp;" + data.description + "<hr>" +
                    "团队已有" + data.numberOfMembers + "人<br>" +
                    "总预算消费：" + data.totalBudget + "元<br>" +
                    "团长预算消费：" + data.personalBudget + "元<br>" +
                    "如果你加入的话目前预算消费：" + (data.totalBudget - data.personalBudget) / data.numberOfMembers + "元<br>";
                (function (gId){
                    $("#inviteMeModelFooterJoin")[0].onclick = function (){
                        $.ajax({
                            url:"./user/join?groupId=" + gId,
                            success:function (result) {
                                var data = eval(result);
                                if (data) {
                                    alert("加入成功！");
                                    location.replace(".");
                                } else {
                                    alert("加入失败！");
                                }
                            }
                        })
                    };
                }(groupId));
                $("#inviteMeModel").modal("show");
            }
        })
    }


</script>
</body>
</html>


